﻿Imports System.Data.SqlClient


Public Class frmBuscaRoles
    Private mstrCondicion As String
    Private mstrValor As String
    Dim mdsDatos As New DataSet
    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Close()
    End Sub
    Public WriteOnly Property Condicion() As String
        Set(ByVal value As String)
            mstrCondicion = value
        End Set
    End Property
    Public ReadOnly Property Valor() As String
        Get
            Valor = mstrValor
        End Get
    End Property
    Private Sub dgResult_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgRoles.CellDoubleClick

        frmE_Roles.dgRoles.CurrentRow.Cells(0).Value = dgRoles.CurrentRow.Cells(0).Value
        Close()


    End Sub
    Sub ActualizarTodas()
        Windows.Forms.Cursor.Current = Cursors.WaitCursor
        dgRoles.Rows.Clear()

        Dim strNombre As String
        Dim cnconn As New SqlConnection
        Dim strSql As String = ""
        Dim cmdBuscar As New SqlCommand
        Dim cmdAsignar As New SqlCommand
        Dim rdBuscar As SqlDataReader
        Dim fecha As Date

        Try
            strNombre = UCase(txtbuscar.Text.Trim)
            strNombre = "%" & strNombre.Replace(" ", "%") & "%"

            cnconn.ConnectionString = OptocontrolConnection
            cnconn.Open()

            cmdBuscar.Connection = cnconn
            cmdAsignar.Connection = cnconn

            strSql = "SELECT COD_RUTA,DESCRIPCION,TARIFA_PROMEDIO,COD_SECTOR,COD_ZONA " & _
                     "FROM RUTA R INNER JOIN SECTOR S ON R.ID_SECTOR=S.ID_SECTOR INNER JOIN ZONA Z ON R.ID_ZONA=Z.ID_ZONA " & _
                     "WHERE upper(COD_RUTA) Like '" & strNombre & "' " & mstrCondicion & " OR upper(DESCRIPCION) like '" & strNombre & "' " & mstrCondicion & " ORDER BY DESCRIPCION"

            cmdBuscar.CommandText = strSql
            rdBuscar = cmdBuscar.ExecuteReader

            Do While rdBuscar.Read()
                dgRoles.Rows.Add(rdBuscar("COD_RUTA"), rdBuscar("DESCRIPCION").ToString.Trim, rdBuscar("TARIFA_PROMEDIO").ToString.Trim, rdBuscar("COD_SECTOR"), rdBuscar("COD_ZONA"))
            Loop
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        Finally
            If cnconn.State = ConnectionState.Open Then
                cnconn.Close()
            End If
        End Try





    End Sub

    Private Sub frmBuscaRoles_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ActualizarTodas()

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtbuscar.TextChanged
        ActualizarTodas()
    End Sub
End Class